home *** CD-ROM | disk | FTP | other *** search
/ Game.EXE 2001 February / GAME_2.ISO / utilities / Opera 5.01 / Opera501_final_nonjava.exe / OPERA.JAR / opera / PluginClassLoader.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-12-07  |  3.6 KB  |  128 lines

  1. package opera;
  2.  
  3. import java.net.URL;
  4. import java.net.URLClassLoader;
  5. import java.security.AllPermission;
  6. import java.security.CodeSource;
  7. import java.security.PermissionCollection;
  8. import java.util.PropertyPermission;
  9. import sun.applet.AppletThreadGroup;
  10. import sun.awt.AppContext;
  11.  
  12. public class PluginClassLoader extends URLClassLoader {
  13.    private static RuntimePermission usePolicyPermission = new RuntimePermission("usePolicy");
  14.    private static PropertyPermission browserReadPerm = new PropertyPermission("browser", "read");
  15.    private static PropertyPermission browserVerReadPerm = new PropertyPermission("browser.version", "read");
  16.    private URL codeBase;
  17.    private AppContext appContext = null;
  18.    private ThreadGroup threadGroup = null;
  19.    private int usageCount = 0;
  20.  
  21.    public PluginClassLoader(URL var1) {
  22.       super(new URL[0], ClassLoader.getSystemClassLoader(), new StreamHandlerFactory());
  23.       this.codeBase = var1;
  24.    }
  25.  
  26.    public void addJar(URL var1) {
  27.       ((URLClassLoader)this).addURL(var1);
  28.    }
  29.  
  30.    ThreadGroup getThreadGroup() {
  31.       try {
  32.          if (this.threadGroup == null || this.threadGroup.isDestroyed()) {
  33.             this.threadGroup = new AppletThreadGroup(this.codeBase + "-threadGroup");
  34.             AppContextCreator var1 = new AppContextCreator(this.threadGroup);
  35.             Object var2 = var1.syncObject;
  36.             synchronized(var2) {
  37.                ((Thread)var1).start();
  38.  
  39.                try {
  40.                   var1.syncObject.wait();
  41.                } catch (InterruptedException var5) {
  42.                }
  43.  
  44.                this.appContext = var1.appContext;
  45.             }
  46.  
  47.             Object var8 = null;
  48.          }
  49.       } catch (Exception var7) {
  50.          ((Throwable)var7).printStackTrace(System.err);
  51.       }
  52.  
  53.       return this.threadGroup;
  54.    }
  55.  
  56.    protected void grab() {
  57.       ++this.usageCount;
  58.       this.getThreadGroup();
  59.    }
  60.  
  61.    protected void release() {
  62.       if (this.usageCount > 1) {
  63.          --this.usageCount;
  64.       } else {
  65.          if (this.appContext != null) {
  66.             try {
  67.                this.appContext.dispose();
  68.             } catch (IllegalThreadStateException var9) {
  69.             }
  70.          }
  71.  
  72.          if (this.appContext != null) {
  73.             AppContextCreator var1 = new AppContextCreator(this.threadGroup);
  74.             Object var2 = var1.syncObject;
  75.             synchronized(var2) {
  76.                var1.appContext = this.appContext;
  77.                ((Thread)var1).start();
  78.  
  79.                try {
  80.                   var1.syncObject.wait();
  81.                } catch (InterruptedException var7) {
  82.                }
  83.             }
  84.  
  85.             Object var10 = null;
  86.          }
  87.  
  88.          if (this.threadGroup != null) {
  89.             int var11 = this.threadGroup.activeCount();
  90.             Thread[] var12 = new Thread[var11];
  91.             int var3 = this.threadGroup.enumerate(var12);
  92.  
  93.             for(int var4 = 0; var4 < var3; ++var4) {
  94.                try {
  95.                   var12[var4].interrupt();
  96.                } catch (Throwable var6) {
  97.                   var6.printStackTrace(System.err);
  98.                }
  99.             }
  100.          }
  101.  
  102.          this.usageCount = 0;
  103.          this.appContext = null;
  104.          this.threadGroup = null;
  105.       }
  106.  
  107.    }
  108.  
  109.    public AppContext getAppContext() {
  110.       return this.appContext;
  111.    }
  112.  
  113.    public PermissionCollection getPermissions(CodeSource var1) {
  114.       PermissionCollection var2 = super.getPermissions(var1);
  115.       var2.add(browserReadPerm);
  116.       var2.add(browserVerReadPerm);
  117.       if (var1.getCertificates() != null && !var2.implies(usePolicyPermission) && this.allPermissionsGranted(var1)) {
  118.          var2.add(new AllPermission());
  119.       }
  120.  
  121.       return var2;
  122.    }
  123.  
  124.    boolean allPermissionsGranted(CodeSource var1) {
  125.       return CertificateHandler.checkCertificates(var1);
  126.    }
  127. }
  128.